/*
 * Copyright (C) 2020-present, kinbug All rights reserved.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.gitee.kinbug.sniper.indicator;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;

import com.gitee.kinbug.sniper.common.entity.Bar;
import com.tictactec.ta.lib.Core;
import com.tictactec.ta.lib.MAType;
import com.tictactec.ta.lib.MInteger;

/**
 * -BBW布林带宽度
 * @ClassName: BBWIndicator
 * @author kinbug
 * @date 2021-1-7
 */
public class BBWIndicator {
	
	public static void getValue(List<Bar> barList, final int period, final List<BigDecimal> callback) {
		callback.clear();
		double[] inClose = new double[barList.size()];
		double[] ups = new double[barList.size()];
		double[] mbs = new double[barList.size()];
		double[] dns = new double[barList.size()];
		MInteger outBegIdx = new MInteger();
		MInteger outNBElement = new MInteger();
		for (int i = 0; i < barList.size(); i++) {
			inClose[i] = barList.get(i).getClose().doubleValue();
		}
		Core core = new Core();
		core.bbands(0, barList.size()-1, inClose, 20, 2, 2, MAType.Sma, outBegIdx, outNBElement, ups, mbs, dns);
		
		for (int i = 0; i < dns.length; i++) {
			if (dns[i]>0) {
    			double up =  ups[i];
    			double dn =  dns[i];
    			callback.add(new BigDecimal((up -dn)/barList.get(i+19).getClose().doubleValue()).setScale(3, RoundingMode.DOWN));
			}
		}
	}
}
